/* 
 * Shuriken is the legal property of its developers. Please refer to the
 * COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Shuriken
{
    /// <summary>
    /// Application launcher
    /// </summary>
    public class ApplicationLauncher
    {
        /// <summary>
        /// Launches the application 
        /// </summary>
        /// <param name="args">arguments</param>
        public static void Launch(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (EnsureApplicationConfigured())
            {
                frmHidden.GetInstance().LoadForm(frmHidden.GetInstance(), new EventArgs());
                Application.Run();
            }
        }

        /// <summary>
        /// Returns true if the application already configured
        /// </summary>
        private static bool ApplicationConfigured
        {
            get
            {
                return Properties.Settings.Default.ApplicationFirstRun; 
            }
        }

        /// <summary>
        /// Ensures that the application ran the initial configuration wizard
        /// </summary>
        /// <returns>true if the application configured</returns>
        private static bool EnsureApplicationConfigured()
        {
            // Application configured.
            if (ApplicationLauncher.ApplicationConfigured)
            { 
                return true;
            }

            // Application is not yet configured
            // Let's run the wizard and then set it confiugred if it ran successfully
            if (ApplicationLauncher.CreateInitialConfiguration())
            {
                Properties.Settings.Default.ApplicationFirstRun = true;          
                Properties.Settings.Default.Save();

                return true; 
            }

            return false; 
        }

        /// <summary>
        /// Creates the initial configuration at first run.
        /// </summary>
        /// <returns></returns>
        private static bool CreateInitialConfiguration()
        {
            // System.Windows.Forms.MessageBox.Show("Wizard for first run Comes here!", "Configuration Wizard");

            // PSEUDO CODE IS COMING HERE 
            // using(WaitCursor cursor1 = new WaitCursor)
            // {
            // if(ApplicationConfigurationWizardController.Welcome(Win32WindowImpl.DesktopWin32Window)!=null)
            // {
            //   return true; 
            // }
            // }
            return true; 
        }
    }
}
